package com.atguigu.exceptionhandls;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    //处理空指针异常
    @ExceptionHandler(NullPointerException.class)
    public String nullExceptionHandler() {
        //在控制台输出日志
        System.out.println("空指针异常");
        return "空指针异常了";
    }

    @ExceptionHandler(Exception.class)
    public String exceptionHandler(Exception e) {
        System.out.println("出现异常");
        e.printStackTrace();
        return e.getMessage();


    }
}
